package com.umeox.moto.watch.themes.skin.entity;


import android.view.View;
import android.widget.SeekBar;
import android.widget.Switch;

import androidx.appcompat.widget.SwitchCompat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class AttrFactory {

    public static final String BACKGROUND = "background";
    public static final String SEEK_BAR_PROGRESS_DRAWABLE = "progressDrawable";
    public static final String TRACK_COLOR = "trackColor";
    public static final String THUMB = "thumb";
    public static final String TEXT_COLOR = "textColor";
    public static final String LIST_SELECTOR = "listSelector";
    public static final String DIVIDER = "divider";
    public static final String ICON_RES = "iconRes";
    public static final String SRC = "src";
    public static final String HOUR_HAND = "hourHand";
    public static final String MINUTE_HAND = "minuteHand";
    public static final String NAIL_ICON = "nailIcon";
    public static final String SWITCH_TRACK = "track";
    public static final String CARD_BG_COLOR = "cardBackgroundColor";
    public static final String WHEEL_ITEM_COLOR = "itemTextColor";
    public static final String WHEEL_VALUE_COLOR = "valueTextColor";
    public static final String[] ATTRS = {
            "drawableLeft",
            "drawableStart",
            "drawableTop",
            "drawableRight",
            "drawableEnd",
            "drawableBottom"
    };
    public static final List<String> compoundList = new ArrayList<>(Arrays.asList(ATTRS));


    public static SkinAttr get(String attrName, int attrValueRefId, String attrValueRefName, String typeName, View view) {

        SkinAttr mSkinAttr = null;
        if (BACKGROUND.equals(attrName)) {
            mSkinAttr = new BackgroundAttr();
        } else if (SEEK_BAR_PROGRESS_DRAWABLE.equals(attrName)) {
            mSkinAttr = new SeekBarAttr();
        } else if (TRACK_COLOR.equals(attrName)) {
            mSkinAttr = new TrackColorAttr();
        } else if (SWITCH_TRACK.equals(attrName)) {
            mSkinAttr = new SwitchAttr();
        } else if (THUMB.equals(attrName)) {
            if(view instanceof SwitchCompat || view instanceof Switch){
                mSkinAttr = new SwitchAttr();
            }else if(view instanceof SeekBar){
                mSkinAttr = new SeekBarAttr ();
            }
        } else if (TEXT_COLOR.equals(attrName)) {
            mSkinAttr = new TextColorAttr();
        } else if (LIST_SELECTOR.equals(attrName)) {
            mSkinAttr = new ListSelectorAttr();
        } else if (DIVIDER.equals(attrName)) {
            mSkinAttr = new DividerAttr();
        } else if (ICON_RES.equals(attrName)) {
            mSkinAttr = new ActionBarIconAttr();
        } else if (SRC.equals(attrName)) {
            mSkinAttr = new ImageViewSrcAttr();
        } else if (HOUR_HAND.equals(attrName) || MINUTE_HAND.equals(attrName) || NAIL_ICON.equals(attrName)) {
            mSkinAttr = new AnalogClockAttr();
        } else if (CARD_BG_COLOR.equals(attrName)) {
            mSkinAttr = new CardBgColorAttr();
        } else if (WHEEL_ITEM_COLOR.equals(attrName)) {
            mSkinAttr = new WheelItemColorAttr();
        } else if (WHEEL_VALUE_COLOR.equals(attrName)) {
            mSkinAttr = new WheelValueColorAttr();
        } else if (compoundList.contains(attrName)) {
            mSkinAttr = new CompoundAttr();

        } else {
            return null;
        }

        mSkinAttr.attrName = attrName;
        mSkinAttr.attrValueRefId = attrValueRefId;
        mSkinAttr.attrValueRefName = attrValueRefName;
        mSkinAttr.attrValueTypeName = typeName;
        return mSkinAttr;
    }

    /**
     * Check whether the attribute is supported
     *
     * @param attrName
     * @return true : supported <br>
     * false: not supported
     */
    public static boolean isSupportedAttr(String attrName) {
        switch (attrName){
            case BACKGROUND:
            case TEXT_COLOR:
            case LIST_SELECTOR:
            case DIVIDER:
            case ICON_RES:
            case SRC:
            case HOUR_HAND:
            case MINUTE_HAND:
            case NAIL_ICON:
            case SEEK_BAR_PROGRESS_DRAWABLE:
            case THUMB:
            case TRACK_COLOR:
            case CARD_BG_COLOR:
            case WHEEL_ITEM_COLOR:
            case WHEEL_VALUE_COLOR:
                return true;
        }

        return compoundList.contains(attrName);
    }
}
